package com.example4.test7;

/**
 * @Auther: shiquan
 * @Date: 2024/10/16 - 10 - 16 -14:21
 */
public class GirlFriendTest {
    //存储4个女朋友 求平均年龄  统计比平均值低的有几个  并打印信息
    public static void main(String[] args) {
        GirlFriend[] arr = new GirlFriend[4];

        GirlFriend g1 = new GirlFriend("张三",18,"妹子","看书");
        GirlFriend g2 = new GirlFriend("李四",19,"妹子","学习");
        GirlFriend g3 = new GirlFriend("老六",23,"妹子","打游戏");
        GirlFriend g4 = new GirlFriend("小王",28,"妹子","看小说");

        arr[0]=g1;
        arr[1]=g2;
        arr[2]=g3;
        arr[3]=g4;

        int sum=0;
        for (int i = 0; i < arr.length; i++) {
           // i表示数组的索引
            GirlFriend g=arr[i];
            sum = g.getAge()+sum;
        }
        int avg = sum/4;
        //统计比平均值低的有几个  并打印信息
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend g=arr[i];
            if (g.getAge()<avg){
                count++;
                System.out.println(g.getName()+","+g.getAge()+","+g.getGender()+","+g.getHobby());
            }

        }
        System.out.println(count+"个");

    }
}
